/**
 * @license
 * Copyright 2016 E2EMail authors. All rights reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * @fileoverview Tests for the autocomplete directive.
 */

goog.require('e2email.components.autocomplete.module');
goog.require('e2email.components.autocompletedirective');

describe('AutocompleteDirective', function() {

  var $compile, $rootScope;
  var autocompleteService;

  beforeEach(module(e2email.components.autocomplete.module.name));
  beforeEach(module(e2email.components.autocompletedirective.module.name));
  beforeEach(module('components/autocomplete/autocomplete.html'));

  beforeEach(inject(function(_$compile_, _$rootScope_, _autocompleteService_) {
    $compile = _$compile_;
    $rootScope = _$rootScope_;
    autocompleteService = _autocompleteService_;
  }));

  it('Incorporates the correct suggestions', function() {
    var expectedText = '';
    var i;
    for (i = 4; i >= 0; i--) {
      var candidate = 'candidate' + i;
      expectedText += candidate;
      autocompleteService.addCandidate(candidate, i);
    }
    var scope = $rootScope.$new();
    scope['thing'] = 'cand';
    var element = $compile(
        '<autocomplete ac-hint="To" ng-model="thing" ac-done="doit()">' +
            '</autocomplete>')(scope);
    $rootScope.$digest();
    expect(element.text()).toContain(expectedText);
  });

});
